<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /*
            展开运算符： 作用就是展开 (去掉数组或者对象 外层的 中括号或者大括号)

                展开对象
                ...{name:'zhangsan',age:18}  ->  name:'zhangsan',age:18
                展开数组  --把数组转为参数列表
                ...[9,8,7]  ->   9,8,7




        */

        // 展开数组
        let arr = [9, 8, 7];
        console.log(1, 2, 3, 4);
        console.log(arr[0], arr[1], arr[2]);
        // log(9, 8, 7)
        console.log(...arr);

        // var r1 = Math.max(1, 2, 3, 4, 5, 7, 34);
        // Math.max(9, 8, 7)
        var r1 = Math.max(...arr);
        console.log(r1);


        // 合并数组

        let arr1 = [9, 8, 7];
        let arr2 = [6, 5, 4];
        let arr3 = arr1.concat(arr2);
        console.log(arr3);

        // 定义数组的时候 直接合并另一个数组中元素
        // [4, 5, 6, 9, 8, 7]
        let arr4 = [4, 5, 6, ...arr1];
        console.log(arr4);


        // 合并对象
        let obj1 = { name: 'zhangsan', fn() { } };
        //  { age: 18, ...{ name: 'zhangsan',fn(){} } }
        //  { age: 18, name: 'zhangsan' ,fn(){} }
        let obj2 = { age: 18, ...obj1 }
        console.log(obj2);

    </script>

</body>

</html>